package ui;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.example.studyAndroid.R;

import java.util.List;

/**
 * note:
 * User: Shaxj
 * Date: 15-6-29
 * Time: 下午2:38
 */
public class FragmentAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private Context context;
    private List<List<String>> result;

    public FragmentAdapter(Context context, List<List<String>> result) {
        this.inflater = LayoutInflater.from(context);
        this.result = result;
    }

    public void setResult(List<List<String>> result) {
        this.result = result;
    }

    @Override
    public int getCount() {
        return result.size();
    }

    @Override
    public Object getItem(int position) {
        return result.get(position);
    }


    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        List<String> list = result.get(position);
        Holder holder;
        if (null == convertView) {
            convertView = inflater.inflate(R.layout.fragment, null);
            holder = new Holder();
            holder.editText1 = (TextView) convertView.findViewById(R.id.content1);
            holder.editText2 = (TextView) convertView.findViewById(R.id.content2);
            holder.editText3 = (TextView) convertView.findViewById(R.id.content3);
            holder.editText4 = (TextView) convertView.findViewById(R.id.content4);
            holder.editText5 = (TextView) convertView.findViewById(R.id.content5);
            holder.editText6 = (TextView) convertView.findViewById(R.id.content6);

        } else {
            holder = (Holder) convertView.getTag();
        }
        holder.editText1.setText(list.get(0));
        holder.editText2.setText(list.get(1));
        holder.editText3.setText(list.get(2));
        holder.editText4.setText(list.get(3));
        holder.editText5.setText(list.get(4));
        holder.editText6.setText(list.get(5));
        convertView.setTag(holder);
        return convertView;
    }

    public class Holder {
        private TextView editText1;
        private TextView editText2;
        private TextView editText3;
        private TextView editText4;
        private TextView editText5;
        private TextView editText6;
    }
}
